package cleancode.model;

/**
 * Model based on name, which is its primary key.
 */
public abstract class NameBasedModel implements Comparable<NameBasedModel>
{
    private String name;

    public NameBasedModel( String name )
    {
        this.name = name;
    }

    public String getName()
    {
        return name;
    }

    public boolean equals( Object obj )
    {
        return getClass().equals( obj.getClass() ) && name.equals( ( ( NameBasedModel ) obj ).getName() );
    }

    public int hashCode()
    {
        return name.hashCode() + getClass().hashCode();
    }

    public String toString()
    {
        return name;
    }

    public int compareTo( NameBasedModel o )
    {
        return name.compareTo( o.getName() );
    }
}
